//jqGrid的配置信息
$.jgrid.defaults.width = 1000;
$.jgrid.defaults.height = 500;
$.jgrid.defaults.responsive = true;
$.jgrid.defaults.styleUI = 'Bootstrap';


//$.jgrid={
//		defaults:{
//			width :1000,
//			height:500,
//			responsive:true,
//			styleUI:"Bootstrap"
//		}	
//}



//工具集合Tools
window.T = {};

// 获取请求参数
// 使用示例
// location.href = http://localhost:8080/index.html?id=123
// T.p('id') --> 123;
var url = function(name) {
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if(r!=null)return  unescape(r[2]); return null;
};
T.p = url;

//全局配置
$.ajaxSetup({
	dataType: "json",
	contentType: "application/json",
	cache: false
});

function hasPermission(permission) {
//    if (window.parent.permissions.indexOf(permission) > -1) {
//        return true;
//    } else {
//        return false;
//    }
	return true;
}

//重写alert
window.alert = function(msg, callback){
	parent.layer.alert(msg, function(index){
		parent.layer.close(index);
		if(typeof(callback) === "function"){
			callback("ok");
		}
	});
}

//重写confirm式样框
window.confirm = function(msg, callback){
	parent.layer.confirm(msg, {btn: ['确定','取消']},
	function(){//确定事件
		if(typeof(callback) === "function"){
			callback("ok");
		}
	});
}

//选择一条记录
function getSelectedRow(jqGrid) {
	if(isNull(jqGrid)){
		jqGrid="jqGrid";
	}
   
	var selectRowId = $("#" + jqGrid).jqGrid('getGridParam','selrow');
	if(isNull(selectRowId)){
		alert("只能选择一条记录");
    	return ;
	}
	var rowData = $("#"+jqGrid).jqGrid('getRowData',selectRowId);
    
    return rowData;
}

//选择多条记录
function getSelectedRows(jqGrid) {
	if(jqGrid=='' || jqGrid==undefined ||jqGrid==null){
		jqGrid="jqGrid";
	}
    var grid = $("#"+jqGrid);
    var rowKey = grid.getGridParam("selrow");
    if(!rowKey){
    	alert("请选择一条记录");
    	return ;
    }
    
    return grid.getGridParam("selarrrow");
}

//刷新grid
function reloadGrid(gridId,params){
	var postData = $("#"+gridId).jqGrid("getGridParam", "postData");
	$.extend(postData, params);
    $("#jqGrid").jqGrid("setGridParam", { 
        search: true
//        url:url
    }).trigger("reloadGrid", [{page:1}]); 
}

function isNull(obj){
	if(obj=='' || obj==undefined ||obj==null){
		return true;
	}else{
		return false;
	}
}